package com.zr.pojo;

/**
 * @author: peterChen
 * @date: 2019/11/14 14:29
 * @description: com.zr.pojo  返回数据封装结果类
 * @version: 1.0
 */
public class Result {
    private String code;
    private String message;
    private Object data;//返回数据

    public Result(String code, String message) {
        super();  // super来继承接口中的构造方法
        this.code = code;
        this.message = message;
    }

    public Result(String code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static Result success(Object data) {
        return new Result("200", "success", data);
    }

    public static Result sysFail(String message) {
        return new Result("500", message == null ? "Server exception" : message);
    }
    public static Result serviceFail(String message) {
        return new Result("400", message == null ? "serviceFail" : message);
    }
    public static Result customFail(String code, String message) {
        return new Result(code, message == null ? "serviceFail" : message);
    }

    public static Result authFail(String message) {
        return new Result("401", message == null ? "please login" : message);
    }
    public static Result authNullFail(String message) {
        return new Result("403", message == null ? "Insufficient authority" : message);
    }
    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "Result{" +
                "code='" + code + '\'' +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
